package com.fmistuff.threadedcalc;
import java.math.BigInteger;

public enum ExpressionOperands
{
	Add('+', 1),
	Subtract('-', 1),
	Multiply('*', 2),
	Divide('/', 2);
	
	private final int priority;
	private final char symbol;
	private ExpressionOperands(char symbol, int priority)
	{
		this.symbol = symbol;
		this.priority = priority;
	}
	
	public int GetPriority()
	{
		return priority;
	}
	
	public char GetSymbol()
	{
		return symbol;
	}
	
	public BigInteger eval(BigInteger a, BigInteger b)
	{
		switch (symbol)
		{
		case '+':
			return a.add(b);
		case '-':
			return a.subtract(b);
		case '*':
			return a.multiply(b);
		case '/':
			return a.divide(b);
		default:
			return null;
		}
	}
	
	public double GetWeight(double weightA, double weightB)
	{
		switch (symbol)
		{
		case '+':
		case '-':
			return Math.max(weightA, weightB);
		case '*':
			return weightA + weightB;
		case '/':
			return Math.min(0, weightA - weightB);
		default:
			return 0;
		}
	}
}
